/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.user;

import com.nus.dataaccess.dao.base.BaseEntity;
import com.nus.dataaccess.dao.role.RoleType;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author robin.foe
 */


@SuppressWarnings("serial")
@Entity
@Table(name="USER_ROLE")
public class UserRole extends BaseEntity{

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    private Long id;
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}
    @Override
    public Serializable getPk() {return this.getId();}

	/*@Column(name="USER_ACCOUNT_ID")
	private Long userAccountId;
	public Long getUserAccountId() {return userAccountId;}
	public void setUserAccountId(Long userAccountId) {this.userAccountId = userAccountId;}*/

    @Column(name="ROLE_TYPE_ID")
    private Long roleTypeId;
    public Long getRoleTypeId() {return roleTypeId;}
    public void setRoleTypeId(Long roleTypeId) {this.roleTypeId = roleTypeId;}


    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="USER_ID", referencedColumnName="ID")// insertable=false,updatable=false
    private UserAccount userAccount;
    public UserAccount getUserAccount() {return userAccount;}
    public void setUserAccount(UserAccount userAccount) {
    	this.userAccount = userAccount;
//		this.setUserAccountId((userAccount == null) ? null : userAccount.getId());
    }

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="ROLE_TYPE_ID", referencedColumnName="ID",insertable=false,updatable=false)
    private RoleType roleType;
    public RoleType getRoleType() {return roleType;}
    public void setRoleType(RoleType roleType) {
	this.roleType = roleType;
	this.setRoleTypeId(( roleType == null) ? null : roleType.getId());
    }

    /*
    public UserRole(){}
    public UserRole(UserAccount userAccount){
	this.setUserAccount(userAccount);
	this.getUserAccount().getUserRoles().add(this);
    }*/

}
